#pragma once
#include<iostream>
using namespace std;

class Date
{
public:
    Date(int y = 2025, int m = 9, int d = 11) 
    {
        if(y <= 0 || m <= 0 || m > 12 || d <= 0 || d > get_day_of_month(y, m))
        {
            puts("日期非法");
            exit(-1);
        }
        _year = y, _month = m, _day = d; 
    }
    void Print() const
    { printf("%d-%02d-%02d\n", _year, _month, _day); }
    
    bool operator< (const Date& d) const;
    bool operator> (const Date& d) const;
    bool operator== (const Date& d) const;
    bool operator<= (const Date& d) const;
    bool operator>= (const Date& d) const;
    bool operator!= (const Date& d) const;

    Date& operator++ ();
    Date& operator-- ();
    Date operator++ (int);
    Date operator-- (int);

    Date& operator+= (int n);
    Date& operator-= (int n);

    Date operator+(int n) const;
    Date operator-(int n) const;
    int operator- (const Date& d) const;

private:

//friend 修饰的函数没有隐含的this
    friend ostream& operator<< (ostream& out, Date& d);
    friend istream& operator>> (istream& in, Date& d);

    int get_day_of_month(int year, int m)
    {
        static int d[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if(m != 2) return d[m];
        // 特判闰年
        if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            return d[2] + 1;
        else return d[2];
    }
    int _year;
    int _month;
    int _day;
};
